<template>
  <div class="article-page">
    <!-- 第十四部 v-for="item in articles" :key="item.id" -->
    <div
      class="article-item" v-for="item in articles" :key="item.id"
      @click="$router.push(`/detail/${item.id}`)">
      <!-- 第十七部   @click="$router.push(`/detail/${item.id}`)"-->
      
      <div class="head">
        <img src="http://teachoss.itheima.net/heimaQuestionMiniapp/%E5%AE%98%E6%96%B9%E9%BB%98%E8%AE%A4%E5%A4%B4%E5%83%8F%402x.png" alt="" />
        <div class="con">
          <!-- 第十五部 -->
          <p class="title">{{item.stem}}</p>
          <p class="other">{{item.creatorName}} | {{item.createdAt}}</p>
        </div>
      </div>
      
      <div class="body">
        {{item.content}}
      </div>
      <div class="foot">{{item.likeCount}} | {{item.views}}</div>
    </div>
  </div>
</template>

<script>



export default {
  name: 'ArticlePage',
  //十二步：请求数据
  // created(){
  //   this.$axios({
  //     url:'https://mock.boxuegu.com/mock/3083/articles'
  //   }).then(res=>{
  //     console.log(res);
  //   }).catch(err=>{
  //     console.log(err);
  //   })
  // }
  // 十二步的另一种写法：包括解构data，连续结构
  async created(){
    const {data:{result:{rows}}}=await this.$axios({
      url:'https://mock.boxuegu.com/mock/3083/articles'
    })
    console.log(rows);
    //把rows里的数据拿来放article里
    this.articles = rows
    
  },
  //十三步
  data(){
    return{
      articles: []
    }
  //第二十五步
  },
  beforeDestroy(){
    console.log('即将被销毁');
  },
  activated(){
    console.log('被激活了');
  },
  deactivated(){
    console.log('被隐藏了');
  }

};
</script>
<style lang="less" scoped>
.article-page {
  background: #f5f5f5;
}
.article-item {
  margin-bottom: 10px;
  background: #fff;
  padding: 10px 15px;
  .head {
    display: flex;
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;
    }
    .con {
      flex: 1;
      overflow: hidden;
      padding-left: 15px;
      p {
        margin: 0;
        line-height: 1.5;
        &.title {
          text-overflow: ellipsis;
          overflow: hidden;
          width: 100%;
          white-space: nowrap;
        }
        &.other {
          font-size: 10px;
          color: #999;
        }
      }
    }
  }
  .body {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    margin-top: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .foot {
    font-size: 12px;
    color: #999;
    margin-top: 10px;
  }
}
</style>